package com.service.impl;

import com.entity.GoldPoints;
import com.entity.User;
import com.exception.DataAccessException;
import com.exception.ServiceException;
import com.mapper.LoginDateMapper;
import com.service.LoginDateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Date;

@Service
public class LoginDateServiceImpl implements LoginDateService {
    @Autowired
    LoginDateMapper loginDateMapper;


    @Override
    public Date finLoginDateS(User user) throws ServiceException {
        return        loginDateMapper.findLoginDateM(user.getId());
    }

    @Override
    public int UpdateLoginDateByIdS(GoldPoints goldPoints) throws ServiceException {
        int i = 0;
        try {
            i = loginDateMapper.UpdateLoginDateByIdM(goldPoints);
        } catch (Exception e) {
            e.printStackTrace();
            throw  new DataAccessException("数据插入异常");
        }
        if (i != 1){
            throw new ServiceException("插入签到记录失败");
        }
        return i;
    }


    public GoldPoints findFrontSumByUidS(HttpSession session){
        User attribute = (User)session.getAttribute("user");
        System.out.println(attribute);
        Integer id = attribute.getId();
        GoldPoints frontSumByUidM = loginDateMapper.findFrontSumByUidM(id);
        return frontSumByUidM;
    }
}
